package com.dy.design_pattern_study.observer_mode.dome3.observer_code.impl;

import com.dy.design_pattern_study.observer_mode.dome3.notifier_code.Subject;
import com.dy.design_pattern_study.observer_mode.dome3.notifier_code.impl.ConcreteSubject;
import com.dy.design_pattern_study.observer_mode.dome3.observer_code.Observer;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-04-03
 * @Content 观察者实现类
 */
public class ConcreteObserver extends Observer {

    private String name;

    private ConcreteSubject subject;

    public ConcreteObserver(String name, ConcreteSubject subject) {
        this.name = name;
        this.subject = subject;
    }

    @Override
    public void Update() {
        String state = subject.getSubjectState();
        System.out.println("观察者：" + name + ",现在的最新状态是：" + state );
    }

    public ConcreteSubject Subject(){
        return subject;
    }

    public void setSubject(ConcreteSubject subject){
        this.subject = subject;
    }

}
